package com.goldenautumn.prefabricate.activity.cart

import android.annotation.SuppressLint
import android.content.Context
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.DataBindingHolder
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.business.entity.GoodsInfoVO
import com.goldenautumn.prefabricate.databinding.ItemSettlementGoodsBinding
import com.goldenautumn.prefabricate.utils.loadImgUrl
import qncx.external.common.compat.isVisible

class SettlementGoodsAdapter constructor(var line:Int? = 1,var isRefund:String? = null)  : BaseQuickAdapter<GoodsInfoVO, DataBindingHolder<ItemSettlementGoodsBinding>>() {

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: DataBindingHolder<ItemSettlementGoodsBinding>, position: Int, item: GoodsInfoVO?) {
        if(item == null) return
        var mBinding  = holder.binding
        mBinding.cover.loadImgUrl(item.goods_image,16)
        mBinding.title.text = "${item.goods_name}"
        mBinding.spec.text = "${item.goods_sku?.goods_attr}"
        mBinding.price.text = (String.format(context.getString(R.string.currency), "${item?.goods_sku?.goods_price}"))
        mBinding.count.text = "x${item.total_num}"
        line?.let { mBinding.title.setLines(it) }
        mBinding.actionBtn.isVisible(item?.content == "true")
        mBinding.status.isVisible(isRefund != null)
        if(isRefund != null) {
            mBinding.status.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(context, if(isRefund == "0") R.mipmap.ic_after_sales_1 else R.mipmap.ic_after_sales_2),null, null, null)
            mBinding.status.text = if(isRefund == "0") context.getString(R.string.processing_after_sales) else context.getString(R.string.rrocessed_after_sales)
            mBinding.price.setTextColor(ContextCompat.getColor(context,R.color.color_DE0000))
        }
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): DataBindingHolder<ItemSettlementGoodsBinding> {
        return DataBindingHolder(R.layout.item_settlement_goods,parent)
    }

}